1230A - Dawid and Bags of Candies - CodeForces Solution


brute force implementation *800

Please click on ads to support us..

Python Code:

from audioop import reverse
from cmath import *
from dataclasses import dataclass
from math import *
from decimal import *
from collections import *
from re import A
import sys
def _input(): return map(int, input().split())
def _list(): return list(map(int, input().split()))
def _int(): return int(input())



def solves():
    a,b,c,d=_input()
    if (a+b+c+d)%2!=0:
        print("NO")
    else:
        if a+b==c+d or a+c==b+d or a+d==c+b or a+b+c==d or a+b+d==c or a+c+d==b or a+b+c+d==0 or b+c+d==a:
            print("YES")
        else:
            print("NO")
    
t=1
for _ in range(0,t):
    solves()

C++ Code:

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ll long long
using namespace std;

void QuickSilver(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a;}
bool sortysort(pair<ll, ll>& a,pair<ll, ll>& b)
{ if(a.second!=b.second)
        return a.second < b.second;
    else
        return a.first>b.first;
}
string PrintNum(long long n,string s){

    if(n==1) {
        s+= (n & 1);
        return s;}
    PrintNum(n>>1,s);
   s+=(n&1); }

int main() {
    QuickSilver();
vector<ll>v(4);
for(auto&it:v)cin>>it;
    for(int i=0;i<(1<<4);i++){
        ll sum=0,sum2=0;
        for(int j=0;j<4;j++){
            if((i>>j)&1){
               sum+=v[j];
            }
            else sum2+=v[j];
        }
        if(sum==sum2)return cout<<"YES",0;
    }
    cout<<"NO";
        return 0;
}
  		  	     	 	  		     	 				


Comments

Submit
0 Comments
More Questions

1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted
387. First Unique Character in a String
383. Ransom Note
242. Valid Anagram
141. Linked List Cycle
21. Merge Two Sorted Lists
203. Remove Linked List Elements
733. Flood Fill
206. Reverse Linked List
83. Remove Duplicates from Sorted List
116. Populating Next Right Pointers in Each Node
145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree
112. Path Sum
1556A - A Variety of Operations
136. Single Number